package com.block.datapush.service.apipush;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.block.common.enums.BaseTypeInfoEnum;
import com.block.common.enums.ProfitSharingEnum;
import com.block.common.model.dto.ThirdInfoDTO;
import com.block.common.model.param.PushApiKeyParam;
import com.block.common.service.IApplicationInfoService;
import com.block.common.service.LogFactory;
import com.block.common.service.merchant.IMerchantThirdBaseInfoService;
import com.block.datapush.enums.PushStatusEnum;
import com.block.datapush.model.PushQueryParam;
import com.block.datapush.model.dto.NoticeParamDTO;
import com.block.datapush.model.result.ProtocolParamResult;
import com.block.datapush.model.result.PushApiResult;
import com.block.datapush.model.result.StarInfoResult;
import com.block.datapush.service.IPushApi2Service;
import com.block.datapush.service.IPushApiService;
import com.block.datapush.service.IPushExtHandleService;
import com.block.datapush.service.apipush.utils.MobileMd5IsInListUtils;
import com.block.datapush.service.apipush.utils.XinFengUtil;
import com.block.db.entity.*;
import com.block.db.mapper.DataMatchOrderItemMapper;
import com.block.db.mapper.MerchantDataPushInfoMapper;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 *  全授权
 */
@Service
public class XinFengApiSMaskPushService implements IPushApiService,IPushApi2Service, IPushExtHandleService {

    private static final Logger log = LogFactory.getPushLog();

    @Autowired
    IMerchantThirdBaseInfoService merchantThirdBaseInfoService;
    @Autowired
    IApplicationInfoService applicationInfoService;
    @Autowired
    MerchantDataPushInfoMapper merchantDataPushInfoMapper;
    @Autowired
    DataMatchOrderItemMapper dataMatchOrderItemMapper;


    @Override
    public PushApiResult checkUser(String orderNo, PushApiKeyParam pushApiKeyParam, MemberSourceInfo memberSourceInfo, JSONObject extJson) {

        PushApiResult pushApiResult = new PushApiResult();
        pushApiResult.setPushSuccess(false);

        String queryUrl = pushApiKeyParam.getCheckUrl();

        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("phoneMask", memberSourceInfo.getMobile().substring(0,8));
        paramMap.put("userName", memberSourceInfo.getRealname());
        if (memberSourceInfo.getSex() == 1){
            paramMap.put("sex", 1);
        }else {
            paramMap.put("sex", 0);
        }
        paramMap.put("age",memberSourceInfo.getAge());
        paramMap.put("loanMoney",XinFengUtil.getLoanAmount(memberSourceInfo.getLoanAmount()));
        paramMap.put("huaBei",XinFengUtil.getHuaBei(memberSourceInfo.getHuabei()));
        paramMap.put("cityCode",memberSourceInfo.getCityCode());
        paramMap.put("social",XinFengUtil.getShebao(memberSourceInfo.getShebao()));
        paramMap.put("baiTiao",XinFengUtil.getBaiTiao(memberSourceInfo.getBaitiao()));
        paramMap.put("credit", XinFengUtil.getYuqi(memberSourceInfo.getYuqi()));
        paramMap.put("house",XinFengUtil.getHouse(memberSourceInfo.getHouse()));
        paramMap.put("termNum",XinFengUtil.getLoanTerm(memberSourceInfo.getLoanTime()));
        paramMap.put("policy",XinFengUtil.getBaoxian(memberSourceInfo.getBaoxian()));
        paramMap.put("education",XinFengUtil.getXueli(memberSourceInfo.getXueli()));
        paramMap.put("car",XinFengUtil.getCar(memberSourceInfo.getCar()));
        paramMap.put("minIncome",XinFengUtil.getShouru(memberSourceInfo.getShouru()));
        paramMap.put("job",XinFengUtil.getJob(memberSourceInfo.getGongzuo()));
        paramMap.put("purpose",XinFengUtil.getLoanUse(memberSourceInfo.getYongtu()));
        paramMap.put("wages",1);
        if(XinFengUtil.getJob(memberSourceInfo.getGongzuo()) == 4){
            paramMap.put("incomeWater",new BigDecimal("500000.00"));
            paramMap.put("busLicense",1);
        }else {
            paramMap.put("incomeWater", new BigDecimal("0.00"));
            paramMap.put("busLicense",0);
        }
        paramMap.put("creditCard",XinFengUtil.getXyk(memberSourceInfo.getXinyongka()));
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateTime = LocalDateTime.now();
        String formattedDateTime = dateTime.format(formatter);
        paramMap.put("clientType",0);
        paramMap.put("applyTime",formattedDateTime);
        paramMap.put("fund",XinFengUtil.getGjj(memberSourceInfo.getGjj()));
        paramMap.put("sesame",XinFengUtil.getZhima(memberSourceInfo.getZhima()));
        paramMap.put("ip", memberSourceInfo.getReqIp());

        //加密
        String encrypt =  XinFengUtil.encryptUtf8(JSON.toJSONString(paramMap),pushApiKeyParam.getApiSecret());

        Map<String, Object> bizMap = new HashMap<>();
        bizMap.put("channelCode",pushApiKeyParam.getApiCode());
        bizMap.put("content",encrypt);

        log.info("【新丰全流程导量】 掩码撞库开始【infoId】{}【infoName】{}【queryUrl】{}【paramMap】{}【bizMap】{}",
                pushApiKeyParam.getInfoId(), pushApiKeyParam.getInfoName(), queryUrl, JSON.toJSONString(paramMap), JSON.toJSONString(bizMap));
        String result = HttpUtil.createPost(queryUrl)
                .header("Content-Type", "application/json")
                .body(JSON.toJSONString(bizMap))
                .execute().body();
        log.info("【新丰全流程导量】 掩码撞库结束【infoId】{}【infoName】{}【result】{}",
                pushApiKeyParam.getInfoId(), pushApiKeyParam.getInfoName(), result);

        JSONObject resultObject = JSON.parseObject(result);
        Integer respCode = resultObject.getInteger("code");
        String respMsg = resultObject.getString("msg");

        pushApiResult.setCode(respCode.toString());
        pushApiResult.setMessage(respMsg);
        pushApiResult.setParamInfo(JSON.toJSONString(paramMap));
        pushApiResult.setResultInfo(result);

        if (!StrUtil.equals(respCode.toString(), "200")) {
            pushApiResult.setPushSuccess(false);
            return pushApiResult;
        }

        // 撞库成功之后，商户的机构数据存储
        JSONObject data = resultObject.getJSONObject("data");
        JSONArray md5List = data.getJSONArray("phoneMd5List");
        String mobileMd5 = memberSourceInfo.getMobileMd5();
        if(MobileMd5IsInListUtils.isMobileMd5InList(md5List,mobileMd5)){
            //如果存在
            pushApiResult.setPushSuccess(false);
            pushApiResult.setCode(respCode+ "|" + "500");
            pushApiResult.setMessage(respMsg + "|" + mobileMd5 +"已存在");
            return pushApiResult;
        }

        if (StrUtil.equals("200",String.valueOf(respCode))) {
            String productName = data.getString("productName");
            String logo = data.getString("logoUrl");
            String productId = data.getString("productId");
            String companyName = data.getString("companyName");
            String orderId = data.getString("orderId");
            // 撞库成功之后，商户的机构数据存储
            ThirdInfoDTO thirdInfoDTO = new ThirdInfoDTO();
            thirdInfoDTO.setInfoId(Integer.valueOf(pushApiKeyParam.getInfoId()));
            thirdInfoDTO.setInfoName(pushApiKeyParam.getInfoName());
            thirdInfoDTO.setOrderNo(orderNo);
            JSONObject infoObject = new JSONObject();
            infoObject.put("orderNo", orderId);
            infoObject.put("productId", productId);
            infoObject.put("productName", productName);
            infoObject.put("companyName", companyName);
            infoObject.put("companyLogo", logo);
            infoObject.put("maxLoanAmount", "200000");
            infoObject.put("maxLoanRate", "20");
            infoObject.put("minLoanRate", "1");
            infoObject.put("businessInfo", pushApiKeyParam.getInfoName());
            JSONArray jsonArray = new JSONArray();
            JSONArray protocolList = data.getJSONArray("authList");
            for (int i = 0; i < protocolList.size(); i++) {
                JSONObject jsonObject = new JSONObject();
                String protocolName = protocolList.getJSONObject(i).getString("authName");
                String protocolUrl = protocolList.getJSONObject(i).getString("authUrl");
                jsonObject.put("protocalName", protocolName);
                jsonObject.put("protocalUrl", protocolUrl);
                jsonArray.add(jsonObject);
            }
            infoObject.put("protocalList", jsonArray);
            thirdInfoDTO.setInfoObject(infoObject);


            //进行分润操作
            String priceType = pushApiKeyParam.getPriceType();
            BigDecimal typeRate = pushApiKeyParam.getTypeRate();
            if (ProfitSharingEnum.PROFITPRICE.getValue().equals(priceType)) {
                BigDecimal price = data.getBigDecimal("sysSellMoney");//下游返回分润前价格
                if (price == null || price.compareTo(new BigDecimal(0.00)) == -1) {
                    pushApiResult.setPushSuccess(false);
                    return pushApiResult;
                }
                BigDecimal priceRight = typeRate.multiply(price);//分润后价格
                pushApiResult.setPrice(price);
                pushApiResult.setPriceRight(priceRight);

            }

            boolean save = merchantThirdBaseInfoService.saveThirdInfo(thirdInfoDTO);
            if (save) {
                pushApiResult.setPushSuccess(true);
                extJson.put("infoObject",infoObject);
                extJson.put("orderId", orderId);
            } else {
                pushApiResult.setMessage("保存撞库数据失败");
            }
        }
        return pushApiResult;
    }

    @Override
    public PushApiResult queryApprove(String orderNo, PushApiKeyParam pushApiKeyParam, MemberSourceInfo memberSourceInfo, JSONObject extJson) {
        return null;
    }

    @Override
    public PushApiResult registerUser(String orderNo, String outOrderNo, PushApiKeyParam pushApiKeyParam, MemberSourceInfo memberSourceInfo, JSONObject extJson) {
        PushApiResult pushApiResult = new PushApiResult();
        pushApiResult.setPushSuccess(false);
        String queryUrl = pushApiKeyParam.getRegisterUrl();
        JSONObject infoObject = extJson.getJSONObject("infoObject");
        String  orderId= infoObject.getString("orderNo");
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("phone", memberSourceInfo.getMobile());
        paramMap.put("orderId", orderId);
        paramMap.put("userName", memberSourceInfo.getRealname());
        if (memberSourceInfo.getSex() == 1){
            paramMap.put("sex", 1);
        }else {
            paramMap.put("sex", 0);
        }
        paramMap.put("age",memberSourceInfo.getAge());
        paramMap.put("loanMoney",XinFengUtil.getLoanAmount(memberSourceInfo.getLoanAmount()));
        paramMap.put("cityCode",memberSourceInfo.getCityCode());
        paramMap.put("huaBei",XinFengUtil.getHuaBei(memberSourceInfo.getHuabei()));
        paramMap.put("social",XinFengUtil.getShebao(memberSourceInfo.getShebao()));
        paramMap.put("baiTiao",XinFengUtil.getBaiTiao(memberSourceInfo.getBaitiao()));
        paramMap.put("credit", XinFengUtil.getYuqi(memberSourceInfo.getYuqi()));
        paramMap.put("house",XinFengUtil.getHouse(memberSourceInfo.getHouse()));
        paramMap.put("termNum",XinFengUtil.getLoanTerm(memberSourceInfo.getLoanTime()));
        paramMap.put("policy",XinFengUtil.getBaoxian(memberSourceInfo.getBaoxian()));
        paramMap.put("education",XinFengUtil.getXueli(memberSourceInfo.getXueli()));
        paramMap.put("car",XinFengUtil.getCar(memberSourceInfo.getCar()));
        paramMap.put("minIncome",XinFengUtil.getShouru(memberSourceInfo.getShouru()));
        paramMap.put("job",XinFengUtil.getJob(memberSourceInfo.getGongzuo()));
        paramMap.put("purpose",XinFengUtil.getLoanUse(memberSourceInfo.getYongtu()));
        paramMap.put("wages",1);
        if(XinFengUtil.getJob(memberSourceInfo.getGongzuo()) == 4){
            paramMap.put("incomeWater",new BigDecimal("500000.00"));
            paramMap.put("busLicense",1);
        }else {
            paramMap.put("incomeWater", new BigDecimal("0.00"));
            paramMap.put("busLicense",0);
        }
        paramMap.put("creditCard",XinFengUtil.getXyk(memberSourceInfo.getXinyongka()));
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        paramMap.put("applyTime", LocalDateTime.now().format(formatter));
        paramMap.put("clientType",0);
        paramMap.put("fund",XinFengUtil.getGjj(memberSourceInfo.getGjj()));
        paramMap.put("sesame",XinFengUtil.getZhima(memberSourceInfo.getZhima()));
        paramMap.put("ip", memberSourceInfo.getReqIp());
        JSONArray authList = new JSONArray();
        
        JSONArray protocalList = infoObject.getJSONArray("protocalList");
        for (int i = 0; i < protocalList.size(); i++) {
            JSONObject jsonObject = new JSONObject();
            String protocolName = protocalList.getJSONObject(i).getString("protocalName");
            String protocolUrl = protocalList.getJSONObject(i).getString("protocalUrl");
            jsonObject.put("authName", protocolName);
            jsonObject.put("authUrl", protocolUrl);
            authList.add(jsonObject);
        }
        paramMap.put("authList", authList);
        //加密
        String encrypt =  XinFengUtil.encryptUtf8(JSON.toJSONString(paramMap),pushApiKeyParam.getApiSecret());

        Map<String, Object> bizMap = new HashMap<>();
        bizMap.put("channelCode",pushApiKeyParam.getApiCode());
        bizMap.put("content",encrypt);

        log.info("【新丰全流程导量】 掩码进件开始【infoId】{}【infoName】{}【queryUrl】{}【paramMap】{}【bizMap】{}",
                pushApiKeyParam.getInfoId(), pushApiKeyParam.getInfoName(), queryUrl, JSON.toJSONString(paramMap), JSON.toJSONString(bizMap));
        String result = HttpUtil.createPost(queryUrl)
                .header("Content-Type", "application/json")
                .body(JSON.toJSONString(bizMap))
                .execute().body();
        log.info("【新丰全流程导量】 掩码进件结束【infoId】{}【infoName】{}【result】{}",
                pushApiKeyParam.getInfoId(), pushApiKeyParam.getInfoName(), result);

        JSONObject resultObject = JSON.parseObject(result);
        Integer respCode = resultObject.getInteger("code");
        String respMsg = resultObject.getString("msg");

        pushApiResult.setCode(respCode.toString());
        pushApiResult.setMessage(respMsg);
        pushApiResult.setParamInfo(JSON.toJSONString(bizMap));
        pushApiResult.setResultInfo(result);

        ThirdInfoDTO thirdInfoDTO = new ThirdInfoDTO();
        thirdInfoDTO.setOrderNo(orderNo);
        thirdInfoDTO.setRetCode(respCode.toString());
        thirdInfoDTO.setRetMsg(respMsg);
        thirdInfoDTO.setResultInfo(result);
        thirdInfoDTO.setStatus("FAILED");

        if (respCode == 200) {
            thirdInfoDTO.setStatus("SUCCESS");
        }
        merchantThirdBaseInfoService.updateThirdInfo(thirdInfoDTO);

        if (respCode == 200) {
            pushApiResult.setPushSuccess(true);
            pushApiResult.setSettleFlag(true);
            pushApiResult.setStatus(PushStatusEnum.SUCCESS.getValue());
            return pushApiResult;
        }
        pushApiResult.setPushSuccess(false);
        pushApiResult.setSettleFlag(false);
        pushApiResult.setStatus(PushStatusEnum.FAILED.getValue());
        return pushApiResult;
    }

    @Override
    public PushApiResult queryResult(PushQueryParam pushQueryParam, PushApiKeyParam pushApiKeyParam, String extJson) {
        PushApiResult pushApiResult = new PushApiResult();
        pushApiResult.setPushSuccess(false);
        return pushApiResult;
    }

    @Override
    public NoticeParamDTO getNoticeResultParam(String infoId, Map<String, String[]> parameterMap, String paramContent) {
        NoticeParamDTO noticeParamDTO = new NoticeParamDTO();
        return noticeParamDTO;
    }

    @Override
    public JSONObject getNoticeResultReturn(Map<String, String[]> parameterMap, String paramContent, JSONObject extObject) {
        JSONObject jsonObject = new JSONObject();
        return jsonObject;
    }

    @Override
    public ProtocolParamResult getProtocolResult(MerchantBaseInfo merchantBaseInfo, MemberSourceInfo memberSourceInfo) {
        ProtocolParamResult paramResult = new ProtocolParamResult();
        return paramResult;
    }

    @Override
    public PushApiResult checkUserCode(String orderNo, PushApiKeyParam pushApiKeyParam, MemberSourceInfo memberSourceInfo, JSONObject extJson) throws Exception {

        PushApiResult pushApiResult = new PushApiResult();
        pushApiResult.setPushSuccess(false);

        String queryUrl = pushApiKeyParam.getCheckUrl();

        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("phoneMask", memberSourceInfo.getMobile().substring(0,8));
        paramMap.put("userName", memberSourceInfo.getRealname());
        if (memberSourceInfo.getSex() == 1){
            paramMap.put("sex", 1);
        }else {
            paramMap.put("sex", 0);
        }
        paramMap.put("age",memberSourceInfo.getAge());
        paramMap.put("loanMoney",XinFengUtil.getLoanAmount(memberSourceInfo.getLoanAmount()));
        paramMap.put("cityCode",memberSourceInfo.getCityCode());
        paramMap.put("huaBei",XinFengUtil.getHuaBei(memberSourceInfo.getHuabei()));
        paramMap.put("social",XinFengUtil.getShebao(memberSourceInfo.getShebao()));
        paramMap.put("baiTiao",XinFengUtil.getBaiTiao(memberSourceInfo.getBaitiao()));
        paramMap.put("credit", XinFengUtil.getYuqi(memberSourceInfo.getYuqi()));
        paramMap.put("house",XinFengUtil.getHouse(memberSourceInfo.getHouse()));
        paramMap.put("termNum",XinFengUtil.getLoanTerm(memberSourceInfo.getLoanTime()));
        paramMap.put("policy",XinFengUtil.getBaoxian(memberSourceInfo.getBaoxian()));
        paramMap.put("education",XinFengUtil.getXueli(memberSourceInfo.getXueli()));
        paramMap.put("car",XinFengUtil.getCar(memberSourceInfo.getCar()));
        paramMap.put("minIncome",XinFengUtil.getShouru(memberSourceInfo.getShouru()));
        paramMap.put("job",XinFengUtil.getJob(memberSourceInfo.getGongzuo()));
        paramMap.put("purpose",XinFengUtil.getLoanUse(memberSourceInfo.getYongtu()));
        paramMap.put("wages",1);
        if(XinFengUtil.getJob(memberSourceInfo.getGongzuo()) == 4){
            paramMap.put("incomeWater",new BigDecimal("500000.00"));
            paramMap.put("busLicense",1);
        }else {
            paramMap.put("incomeWater", new BigDecimal("0.00"));
            paramMap.put("busLicense",0);
        }
        paramMap.put("creditCard",XinFengUtil.getXyk(memberSourceInfo.getXinyongka()));
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateTime = LocalDateTime.now();
        String formattedDateTime = dateTime.format(formatter);
        paramMap.put("clientType",0);
        paramMap.put("applyTime",formattedDateTime);
        paramMap.put("fund",XinFengUtil.getGjj(memberSourceInfo.getGjj()));
        paramMap.put("sesame",XinFengUtil.getZhima(memberSourceInfo.getZhima()));
        paramMap.put("ip", memberSourceInfo.getReqIp());

        //加密
        String encrypt =  XinFengUtil.encryptUtf8(JSON.toJSONString(paramMap),pushApiKeyParam.getApiSecret());

        Map<String, Object> bizMap = new HashMap<>();
        bizMap.put("channelCode",pushApiKeyParam.getApiCode());
        bizMap.put("content",encrypt);

        log.info("【新丰全流程导量】 掩码撞库开始【infoId】{}【infoName】{}【queryUrl】{}【paramMap】{}【bizMap】{}",
                pushApiKeyParam.getInfoId(), pushApiKeyParam.getInfoName(), queryUrl, JSON.toJSONString(paramMap), JSON.toJSONString(bizMap));
        String result = HttpUtil.createPost(queryUrl)
                .header("Content-Type", "application/json")
                .body(JSON.toJSONString(bizMap))
                .execute().body();
        log.info("【新丰全流程导量】 掩码撞库结束【infoId】{}【infoName】{}【result】{}",
                pushApiKeyParam.getInfoId(), pushApiKeyParam.getInfoName(), result);

        JSONObject resultObject = JSON.parseObject(result);
        Integer respCode = resultObject.getInteger("code");
        String respMsg = resultObject.getString("msg");

        pushApiResult.setCode(respCode.toString());
        pushApiResult.setMessage(respMsg);
        pushApiResult.setParamInfo(JSON.toJSONString(paramMap));
        pushApiResult.setResultInfo(result);

        if (!StrUtil.equals(respCode.toString(), "200")) {
            pushApiResult.setPushSuccess(false);
            return pushApiResult;
        }

        // 撞库成功之后，商户的机构数据存储
        JSONObject data = resultObject.getJSONObject("data");
        JSONArray md5List = data.getJSONArray("phoneMd5List");
        pushApiResult.setMd5List(md5List);
        if (StrUtil.equals("200",String.valueOf(respCode))) {
            String productName = data.getString("productName");
            String logo = data.getString("logo");
            String productId = data.getString("productId");
            String companyName = data.getString("companyName");
            String orderId = data.getString("orderId");
            // 撞库成功之后，商户的机构数据存储
            ThirdInfoDTO thirdInfoDTO = new ThirdInfoDTO();
            thirdInfoDTO.setInfoId(Integer.valueOf(pushApiKeyParam.getInfoId()));
            thirdInfoDTO.setInfoName(pushApiKeyParam.getInfoName());
            thirdInfoDTO.setOrderNo(orderNo);
            JSONObject infoObject = new JSONObject();
            infoObject.put("orderNo", orderId);
            infoObject.put("productId", productId);
            infoObject.put("productName", productName);
            infoObject.put("companyName", companyName);
            infoObject.put("companyLogo", logo);
            infoObject.put("maxLoanAmount", "200000");
            infoObject.put("maxLoanRate", "20");
            infoObject.put("minLoanRate", "1");
            infoObject.put("businessInfo", pushApiKeyParam.getInfoName());
            JSONArray jsonArray = new JSONArray();
            JSONArray protocolList = data.getJSONArray("authList");
            for (int i = 0; i < protocolList.size(); i++) {
                JSONObject jsonObject = new JSONObject();
                String protocolName = protocolList.getJSONObject(i).getString("authName");
                String protocolUrl = protocolList.getJSONObject(i).getString("authUrl");
                jsonObject.put("protocalName", protocolName);
                jsonObject.put("protocalUrl", protocolUrl);
                jsonArray.add(jsonObject);
            }
            infoObject.put("protocalList", jsonArray);
            thirdInfoDTO.setInfoObject(infoObject);


            //进行分润操作
            String priceType = pushApiKeyParam.getPriceType();
            BigDecimal typeRate = pushApiKeyParam.getTypeRate();
            if (ProfitSharingEnum.PROFITPRICE.getValue().equals(priceType)) {
                BigDecimal price = data.getBigDecimal("sysSellMoney");//下游返回分润前价格
                if (price == null || price.compareTo(new BigDecimal(0.00)) == -1) {
                    pushApiResult.setPushSuccess(false);
                    return pushApiResult;
                }
                BigDecimal priceRight = typeRate.multiply(price);//分润后价格
                pushApiResult.setPrice(price);
                pushApiResult.setPriceRight(priceRight);

            }

            boolean save = merchantThirdBaseInfoService.saveThirdInfo(thirdInfoDTO);
            if (save) {
                pushApiResult.setPushSuccess(true);
                pushApiResult.setOutOrderNo(orderId);
                extJson.put("orderId", orderId);
            } else {
                pushApiResult.setMessage("保存撞库数据失败");
            }
        }
        return pushApiResult;
    }

    @Override
    public StarInfoResult handleStarInfo(MerchantBaseInfo merchantBaseInfo, Map<String, String[]> parameterMap, String paramContent) throws Exception {
        StarInfoResult starInfoResult = new StarInfoResult();
        JSONObject jsonObjectParamContent = JSONObject.parseObject(paramContent);

        if (ObjectUtil.isEmpty(jsonObjectParamContent)) {
            return starInfoResult;
        }
        String mobileMd5 = jsonObjectParamContent.getString("phoneMd5");
        Integer startLevel = jsonObjectParamContent.getInteger("userLevel");
        starInfoResult.setMobileMd5(mobileMd5);
        starInfoResult.setStarLevel(startLevel);
        return starInfoResult;
    }
}
